package com.ruoyi.voucher.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.voucher.domain.VoucherWord;
import com.ruoyi.voucher.service.IVoucherWordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 凭证字Controller
 * 
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/voucher_word")
public class VoucherWordController extends BaseController
{
    @Autowired
    private IVoucherWordService voucherWordService;

    /**
     * 查询凭证字列表
     */
    @RequiresPermissions("voucher:voucher_word:list")
    @GetMapping("/list")
    public TableDataInfo list(VoucherWord voucherWord)
    {
        startPage();
        List<VoucherWord> list = voucherWordService.selectVoucherWordList(voucherWord);
        return getDataTable(list);
    }

    /**
     * 导出凭证字列表
     */
    @RequiresPermissions("voucher:voucher_word:export")
    @Log(title = "凭证字", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VoucherWord voucherWord)
    {
        List<VoucherWord> list = voucherWordService.selectVoucherWordList(voucherWord);
        ExcelUtil<VoucherWord> util = new ExcelUtil<VoucherWord>(VoucherWord.class);
        util.exportExcel(response, list, "凭证字数据");
    }

    /**
     * 获取凭证字详细信息
     */
    @RequiresPermissions("voucher:voucher_word:query")
    @GetMapping(value = "/{wordId}")
    public AjaxResult getInfo(@PathVariable("wordId") Long wordId)
    {
        return success(voucherWordService.selectVoucherWordByWordId(wordId));
    }

    /**
     * 新增凭证字
     */
    @RequiresPermissions("voucher:voucher_word:add")
    @Log(title = "凭证字", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated VoucherWord voucherWord)
    {
        return toAjax(voucherWordService.insertVoucherWord(voucherWord));
    }

    /**
     * 修改凭证字
     */
    @RequiresPermissions("voucher:voucher_word:edit")
    @Log(title = "凭证字", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VoucherWord voucherWord)
    {
        if (voucherWord.getWordId() == null) {
            throw new RuntimeException("凭证字ID不能为空");
        }
        return toAjax(voucherWordService.updateVoucherWord(voucherWord));
    }

    /**
     * 删除凭证字
     */
    @RequiresPermissions("voucher:voucher_word:remove")
    @Log(title = "凭证字", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wordIds}")
    public AjaxResult remove(@PathVariable Long[] wordIds)
    {
        if (wordIds == null || wordIds.length == 0) {
            throw new RuntimeException("请选择要删除的凭证字");
        }
        return toAjax(voucherWordService.deleteVoucherWordByWordIds(wordIds));
    }


}
